using Light;
using Light.Assets.Scripts.EventManager;
using UnityEngine;

namespace Dream.ThirdLevel
{
    public class TExitDream : MonoBehaviour
    {
        [SerializeField] private bool _isExit;
        [SerializeField] private bool _isEnter;
        [SerializeField] private GameObject keyCOdeF;

        private void Awake()
        {
            _isExit = false;
            _isEnter = false;
            keyCOdeF.SetActive(false);
        }

        private void Update()
        {
            _isExit = LightInputManager.Instance.InteractInput;
            if (_isExit && _isEnter)
            {
                AudioManager.Instance.PauseBGM();
                ExitDream();
            }
        }

        private void OnTriggerEnter2D(Collider2D other)
        {
            if (other.gameObject.CompareTag("Exit"))
            {
                _isEnter = true;
                keyCOdeF.SetActive(true);
            }
        }

        private void OnTriggerExit2D(Collider2D other)
        {
            if (other.gameObject.CompareTag("Exit"))
            {
                _isEnter = false;
                keyCOdeF.SetActive(false);
            }
        }

        private void ExitDream()
        {
            using var evt = NextSceneLoad.Get();
            evt.isFadeScreen = true;
            evt.isExitScene = true;
            EventManager.SendEvent(evt);
            AudioManager.Instance.PauseBGM();
        }
    }
}